<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>
    <!-- 方法一 -->
    请输入一个成绩(0-100之间):
    <input id="score" type="text" /><br />
    <input type="button" value="显示成绩的等级" onclick="fn()" />
    结果：<input id="level" type="text" /><br />
    <!-- <script>
        function fn() {
            var score = parseFloat(document.getElementById("score").value);
            var level = document.getElementById("level").value
            if (score >= 85 && score <= 100) {
                level = "A";
            }
            else if (score >= 70 && score < 85) {
                level = "B";
            }
            else if (score >= 60 && score < 70) {
                level = "C";
            }
            else if (score >= 0 && score < 60) {
                level = "D";
            }
            else {
                level = "E";
            }
            document.getElementById("level").value = level;
        }
    </script> -->
    <!-- 方法二 -->
    <!-- <script>
        function fn() {
            var score = parseFloat(document.getElementById("score").value);
            var level = "";
            switch (true) {
                case score >= 85 && score <= 100: level = "A"; break;
                case score >= 70 && score < 85: level = "B"; break;
                case score >= 60 && score < 70: level = "C"; break;
                case score >= 0 && score < 60: level = "D"; break;
                default: level = "E"; break;
            }
            document.getElementById("level").value = level;
        }
    </script> -->

    <script>
        function getScore(score) {
            var value = ""
            if (score >= 85 && score <= 100) {
                value = "A";
            }
            else if (score >= 70 && score < 85) {
                value = "B";
            }
            else if (score >= 60 && score < 70) {
                value = "C";
            }
            else if (score >= 0 && score < 60) {
                value = "D";
            }
            else {
                value = "E";
            }
            return value;
        }
        // console.log(getScore(85));
        function fn() {
            var result = getScore(document.getElementById("score").value)
            document.getElementById("level").value = result;
        }


    </script>
</body>

</html>